/**
 * fengbin 2007-11-29
 */
package com.wsj.web.action.test;

import java.io.File;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.wsj.util.tool.FileUplaodAndManageForStorage;
import com.wsj.web.form.test.FileUploadForm;

/**
 * @author fengbin
 *
 * create date:2007-11-29
 */
public class FileUploadAction  extends Action{
	
	
	
	FileUplaodAndManageForStorage fileUplaodAndManageForStorage;
	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward execute(
		ActionMapping mapping,
		ActionForm form,
		HttpServletRequest request,
		HttpServletResponse response) {
		
		FileUploadForm  fileUploadForm=(FileUploadForm)form;
		
		
		String uploadPath="fileUpload"+File.separator+"test"+File.separator;
		
		//获取提交的文件
		fileUplaodAndManageForStorage.setMyFiles(fileUploadForm.getMyFile());
		
		
		//设置文件路径
		fileUplaodAndManageForStorage.setPath(uploadPath);
		
		//执行上传,第二个参数:重命名
		String file=fileUplaodAndManageForStorage.uploadFile(request,"");
		
		String path=request.getSession(true).getServletContext().getRealPath(File.separator);
		/***第一个参数:待缩放图片(这个路径可以获取图片的绝对路径)
		 * 第二个参数:重命名图片(带绝对路径)
		 * 第三个参数:缩放比例
		 * 第四个参数:false缩小,true放大
		 * 第五个参数:缩放后的图片的名字
		 */
		
		fileUplaodAndManageForStorage.scale(path+uploadPath+file,"",2,false,"small");
		
		return mapping.findForward("success");
	}
	
	
	public FileUplaodAndManageForStorage getFileUplaodAndManageForStorage() {
		return fileUplaodAndManageForStorage;
	}
	public void setFileUplaodAndManageForStorage(
			FileUplaodAndManageForStorage fileUplaodAndManageForStorage) {
		this.fileUplaodAndManageForStorage = fileUplaodAndManageForStorage;
	}
	
	
	
	

}
